package Management.b;

//                                  显示数据库中时间

import java.sql.*;

/**
 * javaFileObjects = fileMgr.getJavaFileObjects(pathname);
 *
 * 编译
 *
 * compiler.getTask(null, fileMgr, null, null, null, javaFileObjects).call();
 *
 * }catch (Exception e) {
 * throw new RuntimeException("编译失败");
 *
 * }finally{
 * if(fileMgr!=null)
 *
 * try {
 * fileMgr.close();
 *
 * } catch (IOException e) {
 * e.printStackTrace();
 *
 * }
 *
 * }
 *
 * }
 *
 * public void loadClass(){
 * try {
 * 例如/usr/java/classes下有一个test.App类，则/usr/java/classes即这个类的根路径，而.class文件的实际位置是/usr/java/classes/test/App.class
 *
 * File clazzPath = new File(basePath);
 *
 * 记录加载.class文件的数量
 *
 * int clazzCount = 0;
 *
 * if (clazzPath.exists() && clazzPath.isDirectory()) {
 * 获取路径长度
 *
 * int clazzPathLen = clazzPath.getAbsolutePath().length() + 1;
 *
 * Stackstack = new Stack<>();
 *
 * stack.push(clazzPath);
 *
 * 遍历类路径
 *
 * while (stack.isEmpty() == false) {
 * File path = stack.pop();
 *
 * File[] classFiles = path.listFiles(new FileFilter() {
 * public boolean accept(File pathname) {
 * return pathname.isDirectory() || pathname.getName().endsWith(".class");
 *
 * }
 *
 * });
 *
 * for (File subFile : classFiles) {
 * if (subFile.isDirectory()) {
 * stack.push(subFile);
 *
 * } else {
 * if (clazzCount++ == 0) {
 * Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
 *
 * boolean accessible = method.isAccessible();
 *
 * try {
 * if (accessible == false) {
 * method.setAccessible(true);
 *
 * }
 *
 * 设置类加载器
 *
 * URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
 *
 * 将当前类路径加入到类加载器 强制将累加入当前classpath中
 *
 * method.invoke(classLoader, clazzPath.toURI().toURL());
 *
 * } finally {
 * method.setAccessible(accessible);
 *
 * }
 *
 * }
 *
 * 文件名称
 *
 * String className = subFile.getAbsolutePath();
 *
 * className = className.substring(clazzPathLen, className.length() - 6);
 *
 * className = className.replace(File.separatorChar, '.');
 *
 * 加载Class类
 *
 * SoaLogger.debug(QuartzManger.class,"动态加载[class:{"+className+"}]");
 *
 * }
 *
 * }
 *
 * }
 *
 * }
 *
 * } catch (Exception e) {
 * }
 *
 * }
 *
 * public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, JobExecutionException {
 * String src = "package org.soa.quartz.api.job;"+
 *
 * "public class Job5 implements org.quartz.Job {"+
 *
 * "public void execute(org.quartz.JobExecutionContext context)"+
 *
 * "throws org.quartz.JobExecutionException {"+
 *
 * "System.out.println(\"我是动态添加的jobss\");"+
 *
 * "}"+
 *
 * "}";
 *
 * String src2 = "package liuyi.soa.quartz.api.job;"+
 *
 * "public class Job5 implements org.quartz.Job {"+
 *
 * "public void execute(org.quartz.JobExecutionContext context)"+
 *
 * "throws org.quartz.JobExecutionException {"+
 *
 * "System.out.println(\"我是动态添加的jobss\");"+
 *
 * "}"+
 *
 * "}";
 *
 * final JdkCompiler jdkCompiler = JdkCompiler.INSTA;
 *
 * jdkCompiler.compile(Arrays.asList(src,src2),Arrays.asList("org.soa.quartz.api.job.Job5","liuyi.soa.quartz.api.job.Job5") );
 *
 * jdkCompiler.compile(Arrays.asList(src,src2),Arrays.asList("org.soa.quartz.api.job.Job5","liuyi.soa.quartz.api.job.Job5") );
 *
 * jdkCompiler.loadClass();
 *
 * final Job job = (Job)Class.forName("liuyi.soa.quartz.api.job.Job5").newInstance();
 *
 * final Job job5 = (Job)Class.forName("liuyi.soa.quartz.api.job.Job5").newInstance();
 *
 * job.execute(null);
 *
 * job5.execute(null);
 *
 * new JdkCompiler().loadClass();
 *
 * }
 *
 * }
 * ————————————————

 */

public class TestMain2 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {

            // 1. 加载驱动类 可以省略
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            //2.创建链接  DatabaseName=数据库名
            Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=xie", "sa", "123456");
            //3.创建执行器 预处理执行器
            String sql = "select GETDATE()";
            PreparedStatement ps = conn.prepareStatement(sql);
            //SQL语句
            ResultSet rs = ps.executeQuery();
            //
            while (rs.next()) {
                //循环语句
                //
                Timestamp ts = rs.getTimestamp(1);
                //获取时间
                System.out.println(ts);
                //系统
            }
            //
            conn.close();
            //关闭
        }
}


